<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        p {
            height: 400px;
            border: solid;
            font-size: 3rem;
        }
    </style>

</head>

<body>

    <div id="content">
        <p>p1</p>
        <p>p2</p>
        <p>p3</p>
        <p>p4</p>
        <p>p5</p>
        <p>p6</p>
    </div>

    <script>
        const content = document.getElementById('content');
        // 窗口滚动事件
        window.onscroll = function () {
            // 计算窗口滚动是否触底
            const dis = document.documentElement.scrollHeight - window.pageYOffset - window.innerHeight;
            if (dis < 40) {
                const p = document.createElement('p');
                p.innerHTML = 'new content'
                content.append(p);
            }
        }

    </script>

</body>

</html>